#!/bin/bash

######################################################
# file : 
# Author : Anil Kainikara (anilkumar911@gmail.com)
# 
#
# This code is licenced under the GPL.
#
######################################################


export month=
export year=

diarydb="/home/anil/.local/share/diary.db"

usage()
{
  echo "Usage : $0 mm/yyyy"
}

parsedate()
{
  date=$1
  if [[ -z $date ]]
  then
    date=`date +%m/%Y`;
  fi
  month=`echo $date | cut -d'/' -f1`
  year=`echo $date | cut -d'/' -f2`
}

cleanup()
{
  rm -f ${tmp_folder}/diary${DATE_Y2H}.content
  #rm -f ${tmp_folder}/diary${DATE_Y2H}.content.new
}

main()
{
    parsedate $@
    endaction="create"
    #echo $day " " $month " " $year
    sqlite3 $diarydb "select day,month,year,content from entries where month=$month and year=$year;" |
    awk ' /^[0-9]+\|[0-9]+\|[0-9][0-9][0-9][0-9]\|/ { print "#########################################\n" $0 "\n#########################################\n"}
          $0 !~ /^[0-9]+\|[0-9]+\|[0-9][0-9][0-9][0-9]\|/ { print $0 } ' 
    echo ${tmp_folder}/diary${DATE_Y2H}.report
}

main $@
